
#ifndef DL_DEFINITIONS_H
#define DL_DEFINITIONS_H


#include "../network_layer/nw_definitions.h"
#include <cnetsupport.h>


//variable storage for data from network layer (part of or a full paket)
typedef struct {
    char         data[sizeof(PACKET)];
} INFO;

typedef struct {
	unsigned char		 last_segment;		//true iff that segment is the last for the current network layer paket
    INFO		 info;				// info from the upper layer
} FRAME;



/*
 * struct storing outgoing link-related information like packet buffers
 */
typedef struct {

	/*
	 * SPLITTING
	 */
	
	INFO*			curr_info;			//current packet
	size_t				infolen;			//length of the current info (i.e., pktlen)
	size_t			s_max_chunk;		//biggest possible info chunk
	
	unsigned char			seq;
	
	
	int				c_curr_part;		//number of the packet part pushed last in the link
	bool			f_pkt_finished;		//true iff all packet parts were processed
	bool			f_link_ready;		//true iff link is ready to send new data
	
	int				c_total_parts;		//total number of chunks for the current packet
	size_t			s_last_chunk;		//size of the last chunk (often != s_max_chunk)
	            
	QUEUE			buffer;				//packet buffer
	int				S_BUFFER;			//buffer size
		
	CnetTimerID		lasttimer;			//timer to determine when the link is free again
	
	int				link_cost;			
	
} OUT_LINK_DATA;


/*
 * struct storing outgoing link-related information like packet buffers
 */
typedef struct {
	
	/* 
	 * SPLITTING
	 */
	INFO			curr_info;			//current packet (only temp, since we need more later; r for receive)
	int				c_curr_part;
	size_t				infolen;
	unsigned char			seq;
	size_t			s_max_chunk;		//biggest possible info chunk
	
} INC_LINK_DATA;

	
//some useful sizing functions
#define FRAME_HEADER_SIZE  (sizeof(FRAME) - sizeof(INFO))
#define FRAME_SIZE(f)      (FRAME_HEADER_SIZE + f.len)


#endif
